package com.zabra.zl.ui.entrust.tab.history.presenter;

import com.zabra.zl.App;
import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.OrderListBean;
import com.zabra.zl.ui.entrust.tab.history.contract.TabHistoryContract;
import com.zabra.zl.ui.entrust.tab.history.model.TabHistoryModel;
import com.zabra.zl.utils.SharedPreferencesUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TabHistoryPresenter extends BasePresenter<TabHistoryContract.View> implements TabHistoryContract.Presenter {
    private TabHistoryContract.Model model;
    public TabHistoryPresenter() {
        model=new TabHistoryModel();
    }

    @Override
    public void getData(int dealStatus, int orderid, String startTime, String endTime) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(dealStatus, orderid,startTime,endTime).enqueue(new Callback<OrderListBean>() {
            @Override
            public void onResponse(Call<OrderListBean> call, Response<OrderListBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body());
                SharedPreferencesUtil.getInstance(App.context).putSP("token",response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<OrderListBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
